<!--最美移动人预览模块-->
<template>
  <div class="item-content item-voting">
    <div class="voting-content">
      <div class="content-avatar" @click="personnelDetails(businessData)">
        <img :src="getImageUrl(imageId)" alt="头像" />
        <div
          @click.stop="voteBtn(vote)"
          class="votingBtn"
          :class="{ 'voteActive': vote }"
          :style="{ fontSize: adaptiveFontSize(VOTING_FONTS) }"
        >
          {{ vote ? "✔" : "投票" }}
        </div>
      </div>
      <div class="content-basicInformation" :style="{ fontSize: adaptiveFontSize(INFORMATIONAL_FONTS) }">
        <div>姓名：{{ userName }}</div>
        <div>单位：{{ companyName }}</div>
      </div>
    </div>
  </div>
  <!--人员详情弹窗弹窗-->
  <el-dialog
    v-model="detailsPopUp"
    :title="personnelInformation?.popupTitle"
    width="708"
    center
    align-center
    class="personnelDetails"
    draggable
    destroy-on-close
    :close-on-click-modal="false"
  >
    <div class="content-title">
      <div class="title-name">姓名：{{ personnelInformation?.userName }}</div>
      <div class="title-code">单位：{{ personnelInformation?.companyName }}</div>
      <div class="title-avatar">
        <img :src="getImageUrl(imageId)" alt="头像" />
      </div>
    </div>
    <div class="content-content ql-editor ql-blank" v-html="personnelInformation?.popupContent"> </div>
  </el-dialog>
</template>

<script setup>
import Conf from "@/utils/conf";
import Qs from "qs";
import { toRefs } from "vue";
import avatar from "@/assets/images/avatar.png";
import {
  SCALE_CONFIGURATION,
  VOTING_FONTS,
  INFORMATIONAL_FONTS,
  DEVICE_TYPE,
  PROCESS_TYPE,
} from "@/utils/mockConfiguration/mockConfig";

const { EDIT_STATUS } = PROCESS_TYPE;
const props = defineProps({
  terminalType: {
    type: String,
    required: true,
    default: DEVICE_TYPE.DESKTOP, //DESKTOP:pc端,MOBILE:移动端
  },
  deliveryStatus: {
    type: String,
    required: true,
    default: PROCESS_TYPE.EDIT_STATUS, //EDIT_STATUS:编辑状态,PREVIEW_STATUS:预览状态,DELIVERY_STATUS:下发状态,SUBMISSION_STATUS:提交状态,
  }, //流程状态，默认编辑状态
});

//模块数据
const businessData = defineModel("businessData", {
  type: Object,
  required: false,
});

//投票数据
const vote = defineModel("vote", {
  type: Boolean,
  required: false,
});

//人员详情弹窗状态
const detailsPopUp = ref(false);
//人员信息
const personnelInformation = ref({});
//响应解构人员信息、单位名称和头像ID
const { userName, companyName, imageId } = toRefs(businessData.value);

/**
 * 适配字体
 */
const adaptiveFontSize = computed(() => value => `${value * SCALE_CONFIGURATION[props.terminalType]}rem`);

/**
 * 投票按钮
 * @param value 当前投票状态
 */
const voteBtn = value => props.deliveryStatus !== EDIT_STATUS && (vote.value = !value);

/**
 * 定义获取图片URL的函数
 * @param moduleId 当前模块ID
 */
const getImageUrl = moduleId => {
  if (moduleId === "") {
    return new URL(avatar, import.meta.url).href;
  }
  const queryParams = Qs.stringify({ id: moduleId });
  return `${Conf.VITE_APP_BASE_API}/biz/common/image/loading?${queryParams}`;
};

/**
 * 打开人员详情页面
 * @param item
 */
const personnelDetails = item => {
  personnelInformation.value = item;
  detailsPopUp.value = true;
};
</script>

<style lang="less" scoped>
//最美移动人投票
.item-voting {
  display: flex;
  justify-content: center;
  width: 100%;
  height: 100%;
  .voting-content {
    width: 100%;
    height: 100%;
    background: #fff;
    box-shadow: 0 0 10px 0 #c9adad;
    display: flex;
    flex-direction: column;
    border-radius: 5px;
    //最美移动人头像
    .content-avatar {
      position: relative;
      overflow: hidden;
      flex: 198;
      img {
        width: 100%;
        height: 100%;
        border-radius: 10px 10px 0 0;
      }
      .votingBtn {
        user-select: none;
        background: @buttonColor;
        border-radius: 4px 0 0 0;
        position: absolute;
        bottom: 0;
        right: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        color: #ffffff;
        font-weight: 400;
        cursor: pointer;
        padding: 5px 10px;
      }
      .voteActive {
        background: #fff;
        color: @buttonColor;
        border: 1px solid @buttonColor;
      }
    }
    //最美移动人文字
    .content-basicInformation {
      flex: 32;
      padding: 10px 20px;
      font-weight: 400;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
    }
  }
}
//人员详情弹窗
.personnelDetails {
  .content-title {
    font-size: 20px;
    color: #351d1d;
    font-weight: 700;
    text-align: center;
    margin-bottom: 20px;
    .title-name {
      margin-bottom: 10px;
    }
    .title-code {
      margin-bottom: 20px;
    }
    .title-avatar {
      width: 231px;
      height: 324px;
      margin: 0 auto;
      img {
        width: 100%;
        object-fit: cover;
      }
    }
  }
  .content-content {
    font-size: 18px;
    font-weight: 400;
    white-space: pre-wrap;
  }
}
</style>
